package com.lanou.musicproject.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lanou.musicproject.R;
import com.lanou.musicproject.activity.SeekSingerActivity;
import com.lanou.musicproject.bean.Singer;
import com.lanou.musicproject.utils.MyConfig;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by dllo on 15/10/22.
 */
public class SingerListViewAdapter extends BaseAdapter {
    private List<Singer.DataEntity> data;
    private Context mContext;
    private Singer.DataEntity entity;
    private String url;

    public SingerListViewAdapter(Context c, List<Singer.DataEntity> d) {
        mContext = c;
        data = d;

    }

    public int getCount() {
        return data != null && data.size() > 0 ? data.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return data != null && data.size() > 0 ? data.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.singer_item, null);
            holder = new ViewHolder();
            holder.singer_line = (LinearLayout) convertView.findViewById(R.id.singer_line);
            holder.singer_title = (TextView) convertView.findViewById(R.id.singer_title);
            holder.singer_num = (TextView) convertView.findViewById(R.id.singer_num);
            holder.singer_Pic = (ImageView) convertView.findViewById(R.id.singer_Pic);
            holder.singer_songnum = (TextView) convertView.findViewById(R.id.singer_songnum);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final Singer.DataEntity entity = (Singer.DataEntity) getItem(position);
        if (entity != null) {
            holder.singer_title.setText(entity.getSinger_name());
            holder.singer_num.setText(entity.getSong_num() + "");
            holder.singer_songnum.setText(entity.getAlbum_num() + "");
            url = entity.getPic_url();
            Picasso.with(mContext).load(url).into(holder.singer_Pic);
        }
        return convertView;
    }

    private class ViewHolder {
        private ImageView singer_Pic;
        private TextView singer_title, singer_num, singer_songnum;
        private LinearLayout singer_line;


    }


}
